<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>首页</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap-table.min.css" />
<script type="text/javascript">
var documentList;
var userId = "${user_id}";
var isOpen = 0;
$(function (){
	documentList = $("#documentList").bootstrapTable({
		url : '${_baseUrl}/document/getProjectListOldPage?number='+Math.random()+'&pageNum=index',
		pagination: true,
		pageList: [5, 10, 20, 50],
		clickToSelect:false,
		cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
  		queryParams: queryParams,
        columns: [{
            title: '序号',
            width: 45,
            formatter: function(value, row, index){
            	return index+1;
            }
        }, {
            field: 'id',
            title: 'id',
            visible:false,
            width: 5
        }, {
            field: 'projectsupervision',
            title: 'projectsupervision',
            visible:false,
            width: 5
        },{
            field: 'projectname',
            title: '项目名称',
            width: 100,
            formatter: function(value, row, index){
            	var projectSuper = row.projectsupervision;
            	if(projectSuper == null){
            		projectSuper = "";
            	}
            	if(row.projectstatus == "2" || row.projectstatus == "3"){
           			if(projectSuper.indexOf("${user_id}") >= 0){
           				return "<a onClick=\"checkProject('"+row.id+"','"+row.projectid+"','"+row.projectstatus+"');\" title='"+value+"'>"+value+"</a>"
                        //return "<a onClick=\"checkProject('','','');\" title='"+value+"'>"+subProjectName(value)+"</a>"
                    }else{
               			return "<a onClick=\"gotoProjectAndDocument('"+row.id+"','"+row.projectid+"','"+row.projectstatus+"');\" title='"+value+"'>"+value+"</a>";
               			//return "<a onClick=\"gotoProjectAndDocument('','','');\" title='"+value+"'>"+subProjectName(value)+"</a>";
               		}
               		
               	}else if(row.projectstatus == "4"){
               		return "<a onClick=\"checkProject('"+row.id+"','"+row.projectid+"','"+row.projectstatus+"','"+row.projectstatus+"');\" title='"+value+"'>"+value+"</a>"
               		//return "<a onClick=\"checkProject('','',','');\" title='"+value+"'>"+subProjectName(value)+"</a>"
               	}else{
               		if("1" == row.projectstatus && row.projectmanager == "${user_id}"){
               			return "<a onClick=\"establishMent('"+row.id+"','"+row.projectid+"','"+row.projectGroupId+"','"+row.projectstatus+"');\">"+value+"</a>";
               			//return "<a onClick=\"establishMent('','','"+row.projectGroupId+"','');\">"+subProjectName(value)+"</a>";
               		}else if(projectSuper.indexOf("${user_id}") >= 0){
               			return value;
               		}else{
               			return value;
               		}
               	}
            }
        },{
            field: 'applicationscope',
            title: '适用范围',
            width: 100
        },{
            field: 'documentCount',
            title: '文档总数',
            width: 100
        },{
            field: 'projectstarttime',
            title: '开始时间',
            width: 100,
           /*  formatter:function(value,row,index){
            	if(value == "" || value == null){
            		return value;
            	}else{
            		return value.substring(0,value.length - 3);
            	}
            } */
        },{
            field: 'projectendtime',
            title: '结束时间',
            width: 100,
           /*  formatter:function(value,row,index){
            	if(value == "" || value == null){
            		return value;
            	}else{
            		return value.substring(0,value.length - 3);
            	}
            } */
        },{
            field: 'projectstatus',
            title: '进展',
            width: 100,
            formatter: function(value, row, index){
            	if("1" == value)
            		return "未构建";
            	if("2" == value)
            		return "编制中";
            	if("3" == value)
            		return "变更中";
            	if("4" == value)
            		return "已归档";
            }
        },{
            field: 'publishedDocumentPercentage',
            title: '平均编制进度',
            width: 100
        },{
            field: 'projectManagerName',
            title: '项目文档负责人',
            width: 100
        },{
            field: 'documenttemplateName',
            title: '模板名称',
            width: 100,
            formatter : function(value, row, index) {
            	if(value == null){
            		value = "-";
            	}
            	return "<div title='"+value+"'>"+value+"</div>";
            }
        }],onLoadSuccess:function(data){
           if(isOpen == 1){
        	   $("#selectProjectSchedule").show();
           }
           var cellIndex=parseInt($(".table_inline th").length);
           $(".table_inline tr td").each(function(){
               if(this.cellIndex != cellIndex){
                   $(this).attr("title",$(this).text());
               }
           });
        },
    });	
	
	function queryParams(params){
		return {
		    pageSize: params.limit,
		    pageNo: params.pn,
		    sort : params.sort,
		    order : params.order,
		    projectname : $("#projectname").val() == "请输入" ? null : $("#projectname").val(),
	   }
	}
	
	/* 待办事项 */
	$("#handMessage").click(function (){
		parent.showHandMessageKd();
	});
	
	//待阅事项
	$("#readMessage").click(function (){
		parent.showReadMessageKd();
	});
	
});
function selectProjectSchedule(){
	var selected = documentList.bootstrapTable('getSelections');	
	if(selected.length == 0){
		layer.msg("请至少选择一个项目");
		return;
	}
	
	var ids = [];
	
	var jsonData = [];
	
	for(var i = 0; i < selected.length; i++){
		ids.push(selected[i].projectid);
		var  percentage = selected[i].publishedDocumentPercentage;
		percentage = percentage.replace("%","");
		jsonData.push(selected[i].projectid+"-"+percentage);
	}
	var path;
	var title;
	if(selected.length == 1){
		path = "${_baseUrl}/document/showSingleProjectSchedule?projectId="+selected[0].projectid+"&rand="+Math.random();
		title = "项目文档编制进度报告";
	}else{
		path = "${_baseUrl}/document/showAllProjectSchedule?projectIds="+ids.join(",")+"&jsonData="+jsonData.join(",")+"&rand="+Math.random();
		title = "项目进度报告";
	} 

   layerIndex = layer.open({
		 type: 2,
		 title: title,
		 area: ['700px', '500px'],
		 fixed: false, //不固定
		 maxmin: true,
		 shim: true,
		 content:path
   });
   layer.full(layerIndex);
}

/* 项目名称缺省显示 */
/*function subProjectName(name){
	if(name.length > 13){
		name = name.substring(0,13);
		name += "...";
	}
	return name;
} */

//跳转到构建项目页面
function establishMent(id,projectId,projectGroupId,projectstatus){
	 if(projectGroupId == '' || projectGroupId == 'null'){
         layer.msg( "请先设置项目");
         return;
    }
	  parent.parent.parent.skipModule1("文档开发","${_baseUrl}/jurisdiction/menuList",'ae454bee83cf48cdb7c579b81f658044',"a51971151f424fc5ab67437b181d7efb",projectId,id,projectstatus);

}
/**
function checkProject(id,projectId,projectstatus){
	  parent.parent.parent.skipModule1("文档开发","${_baseUrl}/jurisdiction/menuList",'ae454bee83cf48cdb7c579b81f658044',"a51971151f424fc5ab67437b181d7efb",projectId,id,projectstatus);

}**/

function checkProject(id,projectId,projectStatus){
    if(projectStatus == '4'){
        var path="${_baseUrl}/documentList/showProjectAndDocument?projectId="+projectId+"&id="+id+"&status="+projectStatus;
    }else{
        var path="${_baseUrl}/documentList/showProjectAndDocument?projectId="+projectId+"&id="+id+"&projectsupervision=yes";
    }

    window.location.href=path+"&rand="+Math.random();
}
/**
function gotoProjectAndDocument(id,projectId,source){
    var path="${_baseUrl}/documentList/showProjectAndDocument?projectId="+projectId+"&id="+id+"&source="+source;
    window.location.href=path;
}**/

function gotoProjectAndDocument(id,projectId,projectstatus){
	  parent.parent.parent.skipModule1("文档开发","${_baseUrl}/documentList/showProjectAndDocument",'ae454bee83cf48cdb7c579b81f658044',"a51971151f424fc5ab67437b181d7efb",projectId,id,projectstatus);
}

/* 下载文档模板 */
function checkFun(id){
	window.location.href="${_baseUrl}/docModel/checkDownload?id="+id+"&rand="+Math.random();
}
function refreshTable(){
	documentList.bootstrapTable('refresh');
}

document.onkeydown=function(event)
{
    e = event ? event :(window.event ? window.event : null);
    if(e.keyCode==13){
        refreshTable();
    }
}

</script>
<style type="text/css">
	.fixed-table-container{border:0}
	.table_inline tbody tr td div{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
</style>
</head>
<body>
	<div>
	  	<div class="advanced_search">
    		<div class="advanced_search_div"></div>
             <input type="text" name="projectname" id="projectname" value="" placeholder="请输入项目名称" />
              <a class="magnifier" id="search" href="javascript:;"   onclick="refreshTable()"></a>
        </div>
      <div style="overflow: auto; width:98%;margin: auto;">
	     <table class="table table-bordered table_inline" id="documentList"></table>           
    </div>
</div> 
</body>
</html>